🥑
Airbnb JavaScript Style Guide
Note: this guide assumes you are using [Babel](https: //babeljs.io), and requires that you use [babel-preset-airbnb](https: //npmjs.com/babel-preset-airbnb) or the equivalent. It also assumes you are installing shims/polyfills in your app, with [airbnb-browser-shims](https: //npmjs.com/airbnb-browser-shims) or the equivalent.
[![Downloads](https: //img.shields.io/npm/dm/eslint-config-airbnb.svg)](https: //www.npmjs.com/package/eslint-config-airbnb) [![Downloads](https: //img.shields.io/npm/dm/eslint-config-airbnb-base.svg)](https: //www.npmjs.com/package/eslint-config-airbnb-base) [![Gitter](https: //badges.gitter.im/Join%20Chat.svg)](https: //gitter.im/airbnb/javascript)
This guide is available in other languages too. See Translation
Other Style Guides
  • [ES5 (Deprecated)](https: //github.com/airbnb/javascript/tree/es5-deprecated/es5)
  • React
  • CSS-in-JavaScript
  • [CSS & Sass](https: //github.com/airbnb/css)
  • [Ruby](https: //github.com/airbnb/ruby)

Table of Contents

  1. 1.
    Types
  2. 2.
    References
  3. 3.
    Objects
  4. 4.
    Arrays
  5. 5.
    Destructuring
  6. 6.
    Strings
  7. 7.
    Functions
  8. 8.
    Arrow Functions
  9. 9.
    Classes & constructors
  10. 10.
    Modules
  11. 11.
    Iterators and Generators
  12. 12.
    Properties
  13. 13.
    Variables
  14. 14.
    Hoisting
  15. 15.
    Comparison Operators & Equality
  16. 16.
    Blocks
  17. 17.
    Control Statements
  18. 18.
    Comments
  19. 19.
    Whitespace
  20. 20.
    Commas
  21. 21.
    Semicolons
  22. 22.
    Type Casting & Coercion
  23. 23.
    Naming Conventions
  24. 24.
    Accessors
  25. 25.
    Events
  26. 26.
    jQuery
  27. 27.
    ECMAScript 5 Compatibility
  28. 28.
    ECMAScript 6+ (ES 2015+) Styles
  29. 29.
    Standard Library
  30. 30.
    Testing
  31. 31.
    Performance
  32. 32.
    Resources
  33. 33.
    In the Wild
  34. 34.
    Translation
  35. 35.
    The JavaScript Style Guide Guide
  36. 36.
    Chat With Us About JavaScript
  37. 37.
    Contributors
  38. 38.
    License
  39. 39.
    Amendments

Types

  • 1.1 Primitives: When you access a primitive type you work directly on its value.
    • string
    • number
    • boolean
    • null
    • undefined
    • symbol
    • bigint
1
const foo = 1;
2
let bar = foo;
3
4
bar = 9;
5
6
console.log(foo, bar);
7
// => 1, 9
Copied!
1
* Symbols and BigInts cannot be faithfully polyfilled, so they should not be used when targeting browsers/environments that don't support them natively.
Copied!
  • 1.2 Complex: When you access a complex type you work on a reference to its value.
    • object
    • array
    • function
1
const foo = [1, 2];
2
3
const bar = foo;
4
5
bar[0] = 9;
6
7
console.log(foo[0], bar[0]);
8
// => 9, 9
Copied!

References

  • 2.1 Use const for all of your references; avoid using var. eslint: [prefer- const](https: //eslint.org/docs/rules/prefer- const.html), [no- const-assign](https: //eslint.org/docs/rules/no- const-assign.html)
    Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.
1
// bad
2
var a = 1;
3
var b = 2;
4
5
// good
6
7
const a = 1;
8
9
const b = 2;
Copied!

--> 2.2 If you must reassign references, use let instead of var. eslint: [no-var](https:

//eslint.org/docs/rules/no-var.html)
1
> Why? `let` is block-scoped rather than function-scoped like `var`.
Copied!
1
// bad
2
var count = 1;
3
if (true) {
4
count += 1;
5
}
6
7
// good, use the let.
8
let count = 1;
9
if (true) {
10
count += 1;
11
}
Copied!

--> 2.3 Note that both let and `

constare block-scoped, whereasvar` is function-scoped.
1
//
2
const and let only exist in the blocks they are defined in.
3
{
4
let a = 1;
5
6
const b = 1;
7
var c = 1;
8
}
9
console.log(a);
10
// ReferenceError
11
console.log(b);
12
// ReferenceError
13
console.log(c);
14
// Prints 1
Copied!
1
In the above code, you can see that referencing `a` and `b` will produce a ReferenceError, while `c` contains the number. This is because `a` and `b` are block scoped, while `c` is scoped to the containing function.
Copied!

Objects

  • 3.1 Use the literal syntax for object creation. eslint: [no-new-object](https: //eslint.org/docs/rules/no-new-object.html)
1
// bad
2
3
const item = new Object();
4
5
// good
6
7
const item = {};
Copied!

--> 3.2 Use computed property names when creating objects with dynamic property names.

1
> Why? They allow you to define all the properties of an object in one place.
Copied!
1
function getKey(k) {
2
return `a key named ${k}`;
3
}
4
5
// bad
6
7
const obj = {
8
id: 5,
9
name: "San Francisco",
10
};
11
obj[getKey("enabled")] = true;
12
13
// good
14
15
const obj = {
16
id: 5,
17
name: "San Francisco",
18
[getKey("enabled")]: true,
19
};
Copied!

--> 3.3 Use object method shorthand. eslint: [object-shorthand](https:

//eslint.org/docs/rules/object-shorthand.html)
1
// bad
2
3
const atom = {
4
value: 1,
5
6
addValue: function (value) {
7
return atom.value + value;
8
},
9
};
10
11
// good
12
13
const atom = {
14
value: 1,
15
16
addValue(value) {
17
return atom.value + value;
18
},
19
};
Copied!

--> 3.4 Use property value shorthand. eslint: [object-shorthand](https:

//eslint.org/docs/rules/object-shorthand.html)
1
> Why? It is shorter and descriptive.
Copied!
1
const lukeSkywalker = "Luke Skywalker";
2
3
// bad
4
5
const obj = {
6
lukeSkywalker: lukeSkywalker,
7
};
8
9
// good
10
11
const obj = {
12
lukeSkywalker,
13
};
Copied!

--> 3.5 Group your shorthand properties at the beginning of your object declaration.

1
> Why? It's easier to tell which properties are using the shorthand.
Copied!
1
const anakinSkywalker = "Anakin Skywalker";
2
3
const lukeSkywalker = "Luke Skywalker";
4
5
// bad
6
7
const obj = {
8
episodeOne: 1,
9
twoJediWalkIntoACantina: 2,
10
lukeSkywalker,
11
episodeThree: 3,
12
mayTheFourth: 4,
13
anakinSkywalker,
14
};
15
16
// good
17
18
const obj = {
19
lukeSkywalker,
20
anakinSkywalker,
21
episodeOne: 1,
22
twoJediWalkIntoACantina: 2,
23
episodeThree: 3,
24
mayTheFourth: 4,
25
};
Copied!

--> 3.6 Only quote properties that are invalid identifiers. eslint: [quote-props](https:

//eslint.org/docs/rules/quote-props.html)
1
> Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines.
Copied!
1
// bad
2
3
const bad = {
4
foo: 3,
5
bar: 4,
6
"data-blah": 5,
7
};
8
9
// good
10
11
const good = {
12
foo: 3,
13
bar: 4,
14
"data-blah": 5,
15
};
Copied!

--> 3.7 Do not call Object.prototype methods directly, such as hasOwnProperty, propertyIsEnumerable, and isPrototypeOf. eslint: [no-prototype-builtins](https:

//eslint.org/docs/rules/no-prototype-builtins)
1
> Why? These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }` - or, the object may be a null object (`Object.create(null)`).
Copied!
1
// bad
2
console.log(object.hasOwnProperty(key));
3
4
// good
5
console.log(Object.prototype.hasOwnProperty.call(object, key));
6
7
// best
8
9
const has = Object.prototype.hasOwnProperty;
10
// cache the lookup once, in module scope.
11
console.log(has.call(object, key));
12
/* or */
13
import has from "has";
14
// https:
15
//www.npmjs.com/package/has
16
console.log(has(object, key));
Copied!

--> 3.8 Prefer the object spread syntax over [Object.assign](https:

//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to shallow-copy objects. Use the object rest parameter syntax to get a new object with certain properties omitted. eslint: [prefer-object-spread](https: //eslint.org/docs/rules/prefer-object-spread)
1
// very bad
2
3
const original = { a: 1, b: 2 };
4
5
const copy = Object.assign(original, { c: 3 });
6
// this mutates `original` ಠ_ಠ
7
delete copy.a;
8
// so does this
9
10
// bad
11
12
const original = { a: 1, b: 2 };
13
14
const copy = Object.assign({}, original, { c: 3 });
15
// copy => { a: 1, b: 2, c: 3 }
16
17
// good
18
19
const original = { a: 1, b: 2 };
20
21
const copy = { ...original, c: 3 };
22
// copy => { a: 1, b: 2, c: 3 }
23
24
const { a, ...noA } = copy;
25
// noA => { b: 2, c: 3 }
Copied!

Arrays

  • 4.1 Use the literal syntax for array creation. eslint: [no-array- constructor](https: //eslint.org/docs/rules/no-array- constructor.html)
1
// bad
2
3
const items = new Array();
4
5
// good
6
7
const items = [];
Copied!

--> 4.2 Use [Array#push](https:

//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push) instead of direct assignment to add items to an array.
1
const someStack = [];
2
3
// bad
4
someStack[someStack.length] = "abracadabra";
5
6
// good
7
someStack.push("abracadabra");
Copied!

--> 4.3 Use array spreads ... to copy arrays.

1
// bad
2
3
const len = items.length;
4
5
const itemsCopy = [];
6
let i;
7
8
for (i = 0; i < len; i += 1) {
9
itemsCopy[i] = items[i];
10
}
11
12
// good
13
14
const itemsCopy = [...items];
Copied!

--> 4.4 To convert an iterable object to an array, use spreads ... instead of [Array.from](https:

//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
1
const foo = document.querySelectorAll(".foo");
2
3
// good
4
5
const nodes = Array.from(foo);
6
7
// best
8
9
const nodes = [...foo];
Copied!

--> 4.5 Use [Array.from](https:

//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) for converting an array-like object to an array.
1
const arrLike = { 0: "foo", 1: "bar", 2: "baz", length: 3 };
2
3
// bad
4
5
const arr = Array.prototype.slice.call(arrLike);
6
7
// good
8
9
const arr = Array.from(arrLike);
Copied!

--> 4.6 Use [Array.from](https:

//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread ... for mapping over iterables, because it avoids creating an intermediate array.
1
// bad
2
3
const baz = [...foo].map(bar);
4
5
// good
6
7
const baz = Array.from(foo, bar);
Copied!

--> 4.7 Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement returning an expression without side effects, following 8.2. eslint: [array-callback-return](https:

//eslint.org/docs/rules/array-callback-return)
1
// good
2
[1, 2, 3].map((x) => {
3
const y = x + 1;
4
return x * y;
5
});
6
7
// good
8
[1, 2, 3].map((x) => x + 1);
9
10
// bad - no returned value means `acc` becomes undefined after the first iteration
11
[
12
[0, 1],
13
[2, 3],
14
[4, 5],
15
].reduce((acc, item, index) => {
16
const flatten = acc.concat(item);
17
});
18
19
// good
20
[
21
[0, 1],
22
[2, 3],
23
[4, 5],
24
].reduce((acc, item, index) => {
25
const flatten = acc.concat(item);
26
return flatten;
27
});
28
29
// bad
30
inbox.filter((msg) => {
31
const { subject, author } = msg;
32
if (subject === "Mockingbird") {
33
return author === "Harper Lee";
34
} else {
35
return false;
36
}
37
});
38
39
// good
40
inbox.filter((msg) => {
41
const { subject, author } = msg;
42
if (subject === "Mockingbird") {
43
return author === "Harper Lee";
44
}
45
46
return false;
47
});
Copied!

--> 4.8 Use line breaks after open and before close array brackets if an array has multiple lines

1
// bad
2
3
const arr = [
4
[0, 1],
5
[2, 3],
6
[4, 5],
7
];
8
9
const objectInArray = [
10
{
11
id: 1,
12
},
13
{
14
id: 2,
15
},
16
];
17
18
const numberInArray = [1, 2];
19
20
// good
21
22
const arr = [
23
[0, 1],
24
[2, 3],
25
[4, 5],
26
];
27
28
const objectInArray = [
29
{
30
id: 1,
31
},
32
{
33
id: 2,
34
},
35
];
36
37
const numberInArray = [1, 2];
Copied!

Destructuring

  • 5.1 Use object destructuring when accessing and using multiple properties of an object. eslint: [prefer-destructuring](https: //eslint.org/docs/rules/prefer-destructuring)
    Why? Destructuring saves you from creating temporary references for those properties, and from repetitive access of the object. Repeating object access creates more repetitive code, requires more reading, and creates more opportunities for mistakes. Destructuring objects also provides a single site of definition of the object structure that is used in the block, rather than requiring reading the entire block to determine what is used.
1
// bad
2
function getFullName(user) {
3
const firstName = user.firstName;
4
5
const lastName = user.lastName;
6
7
return `${firstName} ${lastName}`;
8
}
9
10
// good
11
function getFullName(user) {
12
const { firstName, lastName } = user;
13
return `${firstName} ${lastName}`;
14
}
15
16
// best
17
function getFullName({ firstName, lastName }) {
18
return `${firstName} ${lastName}`;
19
}
Copied!

--> 5.2 Use array destructuring. eslint: [prefer-destructuring](https:

//eslint.org/docs/rules/prefer-destructuring)
1
const arr = [1, 2, 3, 4];
2
3
// bad
4
5
const first = arr[0];
6
7
const second = arr[1];
8
9
// good
10
11
const [first, second] = arr;
Copied!

--> 5.3 Use object destructuring for multiple return values, not array destructuring.

1
> Why? You can add new properties over time or change the order of things without breaking call sites.
Copied!
1
// bad
2
function processInput(input) {
3
// then a miracle occurs
4
return [left, right, top, bottom];
5
}
6
7
// the caller needs to think about the order of return data
8
9
const [left, __, top] = processInput(input);
10
11
// good
12
function processInput(input) {
13
// then a miracle occurs
14
return { left, right, top, bottom };
15
}
16
17
// the caller selects only the data they need
18
19
const { left, top } = processInput(input);
Copied!

Strings

  • 6.1 Use single quotes '' for strings. eslint: [quotes](https: //eslint.org/docs/rules/quotes.html)
1
// bad
2
3
const name = "Capt. Janeway";
4
5
// bad - template literals should contain interpolation or newlines
6
7
const name = `Capt. Janeway`;
8
9
// good
10
11
const name = "Capt. Janeway";
Copied!

--> 6.2 Strings that cause the line to go over 100 characters should not be written across multiple lines using string concatenation.

1
> Why? Broken strings are painful to work with and make code less searchable.
Copied!
1
// bad
2
3
const errorMessage =
4
"This is a super long error that was thrown because \
5
of Batman. When you stop to think about how Batman had anything to do \
6
with this, you would get nowhere \
7
fast.";
8
9
// bad
10
11
const errorMessage =
12
"This is a super long error that was thrown because " +
13
"of Batman. When you stop to think about how Batman had anything to do " +
14
"with this, you would get nowhere fast.";
15
16
// good
17
18
const errorMessage =
19
"This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.";
Copied!

--> 6.3 When programmatically building up strings, use template strings instead of concatenation. eslint: [prefer-template](https:

//eslint.org/docs/rules/prefer-template.html) [template-curly-spacing](https: //eslint.org/docs/rules/template-curly-spacing)
1
> Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.
Copied!
1
// bad
2
function sayHi(name) {
3
return "How are you, " + name + "?";
4
}
5
6
// bad
7
function sayHi(name) {
8
return ["How are you, ", name, "?"].join();
9
}
10
11
// bad
12
function sayHi(name) {
13
return `How are you, ${name}?`;
14
}
15
16
// good
17
function sayHi(name) {
18
return `How are you, ${name}?`;
19
}
Copied!

--> 6.4 Never use eval() on a string, it opens too many vulnerabilities. eslint: [no-eval](https:

//eslint.org/docs/rules/no-eval)
  • 6.5 Do not unnecessarily escape characters in strings. eslint: [no-useless-escape](https: //eslint.org/docs/rules/no-useless-escape)
    Why? Backslashes harm readability, thus they should only be present when necessary.
1
// bad
2
3
const foo = "'this' is \"quoted\"";
4
5
// good
6
7
const foo = "'this' is \"quoted\"";
8
9
const foo = `my name is '${name}'`;
Copied!

Functions

  • 7.1 Use named function expressions instead of function declarations. eslint: [func-style](https: //eslint.org/docs/rules/func-style)
    Why? Function declarations are hoisted, which means that it's easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function's definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it's time to extract it to its own module! Don't forget to explicitly name the expression, regardless of whether or not the name is inferred from the containing variable (which is often the case in modern browsers or when using compilers such as Babel). This eliminates any assumptions made about the Error's call stack. ([Discussion](https: //github.com/airbnb/javascript/issues/794))
1
// bad
2
function foo() {
3
// ...
4
}
5
6
// bad
7
8
const foo = function () {
9
// ...
10
};
11
12
// good
13
14
// lexical name distinguished from the variable-referenced invocation(s)
15
16
const short = function longUniqueMoreDescriptiveLexicalFoo() {
17
// ...
18
};
Copied!

--> 7.2 Wrap immediately invoked function expressions in parentheses. eslint: [wrap-iife](https:

//eslint.org/docs/rules/wrap-iife.html)
1
> Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE.
Copied!
1
// immediately-invoked function expression (IIFE)
2
(function () {
3
console.log("Welcome to the Internet. Please follow me.");
4
})();
Copied!

--> 7.3 Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [no-loop-func](https:

//eslint.org/docs/rules/no-loop-func.html)
  • 7.4 Note: ECMA-262 defines a block as a list of statements. A function declaration is not a statement.
1
// bad
2
if (currentUser) {
3
function test() {
4
console.log("Nope.");
5
}
6
}
7
8
// good
9
let test;
10
if (currentUser) {
11
test = () => {
12
console.log("Yup.");
13
};
14
}
Copied!

--> 7.5 Never name a parameter arguments. This will take precedence over the arguments object that is given to every function scope.

1
// bad
2
function foo(name, options, arguments) {
3
// ...
4
}
5
6
// good
7
function foo(name, options, args) {
8
// ...
9
}
Copied!

--> 7.6 Never use arguments, opt to use rest syntax ... instead. eslint: [prefer-rest-params](https:

//eslint.org/docs/rules/prefer-rest-params)
1
> Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`.
Copied!
1
// bad
2
function concatenateAll() {
3
const args = Array.prototype.slice.call(arguments);
4
return args.join("");
5
}
6
7
// good
8
function concatenateAll(...args) {
9
return args.join("");
10
}
Copied!

--> 7.7 Use default parameter syntax rather than mutating function arguments.

1
// really bad
2
function handleThings(opts) {
3
// No! We shouldn't mutate function arguments.
4
5
// Double bad: if opts is falsy it'll be set to an object which may
6
7
// be what you want but it can introduce subtle bugs.
8
opts = opts || {};
9
10
// ...
11
}
12
13
// still bad
14
function handleThings(opts) {
15
if (opts === void 0) {
16
opts = {};
17
}
18
19
// ...
20
}
21
22
// good
23
function handleThings(opts = {}) {
24
// ...
25
}
Copied!

--> 7.8 Avoid side effects with default parameters.

1
> Why? They are confusing to reason about.
Copied!
1
var b = 1;
2
3
// bad
4
function count(a = b++) {
5
console.log(a);
6
}
7
count();
8
// 1
9
count();
10
// 2
11
count(3);
12
// 3
13
count();
14
// 3
Copied!

--> 7.9 Always put default parameters last. eslint: [default-param-last](https:

//eslint.org/docs/rules/default-param-last)
1
// bad
2
function handleThings(opts = {}, name) {
3
// ...
4
}
5
6
// good
7
function handleThings(name, opts = {}) {
8
// ...
9
}
Copied!

--> 7.10 Never use the Function

constructor to create a new function. eslint: [no-new-func](https: //eslint.org/docs/rules/no-new-func)
1
> Why? Creating a function in this way evaluates a string similarly to `eval()`, which opens vulnerabilities.
Copied!
1
// bad
2
var add = new Function("a", "b", "return a + b");
3
4
// still bad
5
var subtract = Function("a", "b", "return a - b");
Copied!

--> 7.11 Spacing in a function signature. eslint: [space-before-function-paren](https:

//eslint.org/docs/rules/space-before-function-paren) [space-before-blocks](https: //eslint.org/docs/rules/space-before-blocks)
1
> Why? Consistency is good, and you shouldn't have to add or remove a space when adding or removing a name.
Copied!
1
// bad
2
3
const f = function () {};
4
5
const g = function () {};
6
7
const h = function () {};
8
9
// good
10
11
const x = function () {};
12
13
const y = function a() {};
Copied!

--> 7.12 Never mutate parameters. eslint: [no-param-reassign](https:

//eslint.org/docs/rules/no-param-reassign.html)
1
> Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller.
Copied!
1
// bad
2
function f1(obj) {
3
obj.key = 1;
4
}
5
6
// good
7
function f2(obj) {
8
const key = Object.prototype.hasOwnProperty.call(obj, "key") ? obj.key : 1;
9
}
Copied!

--> 7.13 Never reassign parameters. eslint: [no-param-reassign](https:

//eslint.org/docs/rules/no-param-reassign.html)
1
> Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8.
Copied!
1
// bad
2
function f1(a) {
3
a = 1;
4
5
// ...
6
}
7
8
function f2(a) {
9
if (!a) {
10
a = 1;
11
}
12
13
// ...
14
}
15
16
// good
17
function f3(a) {
18
const b = a || 1;
19
20
// ...
21
}
22
23
function f4(a = 1) {
24
// ...
25
}
Copied!

--> 7.14 Prefer the use of the spread syntax ... to call variadic functions. eslint: [prefer-spread](https:

//eslint.org/docs/rules/prefer-spread)
1
> Why? It's cleaner, you don't need to supply a context, and you can not easily compose `new` with `apply`.
Copied!
1
// bad
2
3
const x = [1, 2, 3, 4, 5];
4
console.log.apply(console, x);
5
6
// good
7
8
const x = [1, 2, 3, 4, 5];
9
console.log(...x);
10
11
// bad
12
new (Function.prototype.bind.apply(Date, [null, 2016, 8, 5]))();
13
14
// good
15
new Date(...[2016, 8, 5]);
Copied!

--> 7.15 Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself, with a trailing comma on the last item. eslint: [function-paren-newline](https:

//eslint.org/docs/rules/function-paren-newline)
1
// bad
2
function foo(bar, baz, quux) {
3
// ...
4
}
5
6
// good
7
function foo(bar, baz, quux) {
8
// ...
9
}
10
11
// bad
12
console.log(foo, bar, baz);
13
14
// good
15
console.log(foo, bar, baz);
Copied!

Arrow Functions

  • 8.1 When you must use an anonymous function (as when passing an inline callback), use arrow function notation. eslint: [prefer-arrow-callback](https: //eslint.org/docs/rules/prefer-arrow-callback.html), [arrow-spacing](https: //eslint.org/docs/rules/arrow-spacing.html)
    Why? It creates a version of the function that executes in the context of this, which is usually what you want, and is a more concise syntax.
    Why not? If you have a fairly complicated function, you might move that logic out into its own named function expression.
1
// bad
2
[1, 2, 3].map(function (x) {
3
const y = x + 1;
4
return x * y;
5
});
6
7
// good
8
[1, 2, 3].map((x) => {
9
const y = x + 1;
10
return x * y;
11
});
Copied!

--> 8.2 If the function body consists of a single statement returning an [expression](https:

//developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions) without side effects, omit the braces and use the implicit return. Otherwise, keep the braces and use a return statement. eslint: [arrow-parens](https: //eslint.org/docs/rules/arrow-parens.html), [arrow-body-style](https: //eslint.org/docs/rules/arrow-body-style.html)
1
> Why? Syntactic sugar. It reads well when multiple functions are chained together.
Copied!
1
// bad
2
[1, 2, 3].map((number) => {
3
const nextNumber = number + 1;
4
`A string containing the ${nextNumber}.`;
5
});
6
7
// good
8
[1, 2, 3].map((number) => `A string containing the ${number + 1}.`);
9
10
// good
11
[1, 2, 3].map((number) => {
12
const nextNumber = number + 1;
13
return `A string containing the ${nextNumber}.`;
14
});
15
16
// good
17
[1, 2, 3].map((number, index) => ({
18
[index]: number,
19
}));
20
21
// No implicit return with side effects
22
function foo(callback) {
23
const val = callback();
24
if (val === true) {
25
// Do something if callback returns true
26
}
27
}
28
29
let bool = false;
30
31
// bad
32
foo(() => (bool = true));
33
34
// good
35
foo(() => {
36
bool = true;
37
});
Copied!

--> 8.3 In case the expression spans over multiple lines, wrap it in parentheses for better readability.

1
> Why? It shows clearly where the function starts and ends.
Copied!
1
// bad
2
["get", "post", "put"].map((httpMethod) =>
3
Object.prototype.hasOwnProperty.call(
4
httpMagicObjectWithAVeryLongName,
5
httpMethod
6
)
7
);
8
9
// good
10
["get", "post", "put"].map((httpMethod) =>
11
Object.prototype.hasOwnProperty.call(
12
httpMagicObjectWithAVeryLongName,
13
httpMethod
14
)
15
);
Copied!

--> 8.4 Always include parentheses around arguments for clarity and consistency. eslint: [arrow-parens](https:

//eslint.org/docs/rules/arrow-parens.html)
1
> Why? Minimizes diff churn when adding or removing arguments.
Copied!
1
// bad
2
[1, 2, 3].map((x) => x * x);
3
4
// good
5
[1, 2, 3].map((x) => x * x);
6
7
// bad
8
[1, 2, 3].map(
9
(number) =>
10
`A long string with the ${number}. It's so long that we don't want it to take up space on the .map line!`
11
);
12
13
// good
14
[1, 2, 3].map(
15
(number) =>
16
`A long string with the ${number}. It's so long that we don't want it to take up space on the .map line!`
17
);
18
19
// bad
20
[1, 2, 3].map((x) => {
21
const y = x + 1;
22
return x * y;
23
});
24
25
// good
26
[1, 2, 3].map((x) => {
27
const y = x + 1;
28
return x * y;
29
});
Copied!

--> 8.5 Avoid confusing arrow function syntax (=>) with comparison operators (<=, >=). eslint: [no-confusing-arrow](https:

//eslint.org/docs/rules/no-confusing-arrow)
1
// bad
2
3
const itemHeight = (item) =>
4
item.height <= 256 ? item.largeSize : item.smallSize;
5
6
// bad
7
8
const itemHeight = (item) =>
9
item.height >= 256 ? item.largeSize : item.smallSize;
10
11
// good
12
13
const itemHeight = (item) =>
14
item.height <= 256 ? item.largeSize : item.smallSize;
15
16
// good
17
18
const itemHeight = (item) => {
19
const { height, largeSize, smallSize } = item;
20
return height <= 256 ? largeSize : smallSize;
21
};
Copied!

--> 8.6 Enforce the location of arrow function bodies with implicit returns. eslint: [implicit-arrow-linebreak](https:

//eslint.org/docs/rules/implicit-arrow-linebreak)
1
// bad
2
(foo) => bar;
3
4
(foo) => bar;
5
6
// good
7
(foo) => bar;
8
(foo) => bar;
9
(foo) => bar;
Copied!

Classes &

constructors
  • 9.1 Always use class. Avoid manipulating prototype directly.
    Why? class syntax is more concise and easier to reason about.
1
// bad
2
function Queue(contents = []) {
3
this.queue = [...contents];
4
}
5
Queue.prototype.pop = function () {
6
const value = this.queue[0];
7
this.queue.splice(0, 1);
8
return value;
9
};
10
11
// good
12
class Queue {
13
constructor(contents = []) {
14
this.queue = [...contents];
15
}
16
pop() {
17
const value = this.queue[0];
18
this.queue.splice(0, 1);
19
return value;
20
}
21
}
Copied!

--> 9.2 Use extends for inheritance.

1
> Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`.
Copied!
1
// bad
2
3
const inherits = require("inherits");
4
function PeekableQueue(contents) {
5
Queue.apply(this, contents);
6
}
7
inherits(PeekableQueue, Queue);
8
PeekableQueue.prototype.peek = function () {
9
return this.queue[0];
10
};
11
12
// good
13
class PeekableQueue extends Queue {
14
peek() {
15
return this.queue[0];
16
}
17
}
Copied!

--> 9.3 Methods can return this to help with method chaining.

1
// bad
2
Jedi.prototype.jump = function () {
3
this.jumping = true;
4
return true;
5
};
6
7
Jedi.prototype.setHeight = function (height) {
8
this.height = height;
9
};
10
11
const luke = new Jedi();
12
luke.jump();
13
// => true
14
luke.setHeight(20);
15
// => undefined
16
17
// good
18
class Jedi {
19
jump() {
20
this.jumping = true;
21
return this;
22
}
23
24
setHeight(height) {
25
this.height = height;
26
return this;
27
}
28
}
29
30
const luke = new Jedi();
31
32
luke.jump().setHeight(20);
Copied!

--> 9.4 It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects.

1
class Jedi {
2
constructor(options = {}) {
3
this.name = options.name || "no name";
4
}
5
6
getName() {
7
return this.name;
8
}
9
10
toString() {
11
return `Jedi - ${this.getName()}`;
12
}
13
}
Copied!

--> 9.5 Classes have a default

constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. eslint: [no-useless- constructor](https: //eslint.org/docs/rules/no-useless- constructor)
1
// bad
2
class Jedi {
3
constructor() {}
4
5
getName() {
6
return this.name;
7
}
8
}
9
10
// bad
11
class Rey extends Jedi {
12
constructor(...args) {
13
super(...args);
14
}
15
}
16
17
// good
18
class Rey extends Jedi {
19
constructor(...args) {
20
super(...args);
21
this.name = "Rey";
22
}
23
}
Copied!

--> 9.6 Avoid duplicate class members. eslint: [no-dupe-class-members](https:

//eslint.org/docs/rules/no-dupe-class-members)
1
> Why? Duplicate class member declarations will silently prefer the last one - having duplicates is almost certainly a bug.
Copied!
1
// bad
2
class Foo {
3
bar() {
4
return 1;
5
}
6
bar() {
7
return 2;
8
}
9
}
10
11
// good
12
class Foo {
13
bar() {
14
return 1;
15
}
16
}
17
18
// good
19
class Foo {
20
bar() {
21
return 2;
22
}
23
}
Copied!

--> 9.7 Class methods should use this or be made into a static method unless an external library or framework requires using specific non-static methods. Being an instance method should indicate that it behaves differently based on properties of the receiver. eslint: [class-methods-use-this](https:

//eslint.org/docs/rules/class-methods-use-this)
1
// bad
2
class Foo {
3
bar() {
4
console.log("bar");
5
}
6
}
7
8
9
// good - this is used
10
class Foo {
11
bar() {
12
console.log(this.bar);
13
}
14
}
15
16
17
// good -
18
constructor is exempt
19
class Foo {
20
21
constructor() {
22
23
// ...
24
}
25
}
26
27
28
// good - static methods aren't expected to use this
29
class Foo {
30
static bar() {
31
console.log("bar");
32
}
33
}
Copied!

Modules

  • 10.1 Always use modules (import/export) over a non-standard module system. You can always transpile to your preferred module system.
    Why? Modules are the future, let's start using the future now.
1
// bad
2
3
const AirbnbStyleGuide = require('./AirbnbStyleGuide');
4
module.exports = AirbnbStyleGuide.es6;
5
6
7
// ok
8
import AirbnbStyleGuide from './AirbnbStyleGuide';
9
export default AirbnbStyleGuide.es6;
10
11
12
// best
13
import { es6 } from './AirbnbStyleGuide';
14
export default es6;
Copied!

--> 10.2 Do not use wildcard imports.

1
> Why? This makes sure you have a single default export.
Copied!
1
// bad
2
import * as AirbnbStyleGuide from "./AirbnbStyleGuide";
3
4
// good
5
import AirbnbStyleGuide from "./AirbnbStyleGuide";
Copied!

--> 10.3 And do not export directly from an import.

1
> Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent.
Copied!
1
// bad
2
3
// filename es6.js
4
export { es6 as default } from './AirbnbStyleGuide';
5
6
7
// good
8
9
// filename es6.js
10
import { es6 } from './AirbnbStyleGuide';
11
export default es6;
Copied!

--> 10.4 Only import from a path in one place. eslint: [no-duplicate-imports](https:

//eslint.org/docs/rules/no-duplicate-imports)
1
> Why? Having multiple lines that import from the same path can make code harder to maintain.
Copied!
1
// bad
2
import foo from "foo";
3
4
// … some other imports …
5
//
6
import { named1, named2 } from "foo";
7
8
// good
9
import foo, { named1, named2 } from "foo";
10
11
// good
12
import foo, { named1, named2 } from "foo";
Copied!

--> 10.5 Do not export mutable bindings. eslint: [import/no-mutable-exports](https:

//github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md)
1
> Why? Mutation should be avoided in general, but in particular when exporting mutable bindings. While this technique may be needed for some special cases, in general, only
2
constant references should be exported.
Copied!
1
// bad
2
let foo = 3;
3
export { foo };
4
5
// good
6
7
const foo = 3;
8
export { foo };
Copied!

--> 10.6 In modules with a single export, prefer default export over named export. eslint: [import/prefer-default-export](https:

//github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md)
1
> Why? To encourage more files that only ever export one thing, which is better for readability and maintainability.
Copied!
1
// bad
2
export function foo() {}
3
4
// good
5
export default function foo() {}
Copied!

--> 10.7 Put all imports above non-import statements. eslint: [import/first](https:

//github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md)
1
> Why? Since `import`s are hoisted, keeping them all at the top prevents surprising behavior.
Copied!
1
// bad
2
import foo from "foo";
3
foo.init();
4
5
import bar from "bar";
6
7
// good
8
import foo from "foo";
9
import bar from "bar";
10
11
foo.init();
Copied!

--> 10.8 Multiline imports should be indented just like multiline array and object literals. eslint: [object-curly-newline](https:

//eslint.org/docs/rules/object-curly-newline)
1
> Why? The curly braces follow the same indentation rules as every other curly brace block in the style guide, as do the trailing commas.
Copied!
1
// bad
2
import { longNameA, longNameB, longNameC, longNameD, longNameE } from "path";
3
4
// good
5
import { longNameA, longNameB, longNameC, longNameD, longNameE } from "path";
Copied!

--> 10.9 Disallow Webpack loader syntax in module import statements. eslint: [import/no-webpack-loader-syntax](https:

//github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md)
1
> Why? Since using Webpack syntax in the imports couples the code to a module bundler. Prefer using the loader syntax in `webpack.config.js`.
Copied!
1
// bad
2
import fooSass from "css!sass!foo.scss";
3
import barCss from "style!css!bar.css";
4
5
// good
6
import fooSass from "foo.scss";
7
import barCss from "bar.css";
Copied!

--> 10.10 Do not include JavaScript filename extensions eslint: [import/extensions](https:

//github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md)
1
> Why? Including extensions inhibits refactoring, and inappropriately hardcodes implementation details of the module you're importing in every consumer.
Copied!
1
// bad
2
import foo from "./foo.js";
3
import bar from "./bar.jsx";
4
import baz from "./baz/index.jsx";
5
6
// good
7
import foo from "./foo";
8
import bar from "./bar";
9
import baz from "./baz";
Copied!

Iterators and Generators

  • 11.1 Don't use iterators. Prefer JavaScript's higher-order functions instead of loops like for-in or for-of. eslint: [no-iterator](https: //eslint.org/docs/rules/no-iterator.html) [no-restricted-syntax](https: //eslint.org/docs/rules/no-restricted-syntax)
    Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
    Use map() / every() / filter() / find() / findIndex() / reduce() / some() / ... to iterate over arrays, and Object.keys() / Object.values() / Object.entries() to produce arrays so you can iterate over objects.
1
const numbers = [1, 2, 3, 4, 5];
2
3
// bad
4
let sum = 0;
5
for (let num of numbers) {
6
sum += num;
7
}
8
sum === 15;
9
10
// good
11
let sum = 0;
12
numbers.forEach((num) => {
13
sum += num;
14
});
15
sum === 15;
16
17
// best (use the functional force)
18
19
const sum = numbers.reduce((total, num) => total + num, 0);
20
sum === 15;
21
22
// bad
23
24
const increasedByOne = [];
25
for (let i = 0; i < numbers.length; i++) {
26
increasedByOne.push(numbers[i] + 1);
27
}
28
29
// good
30
31
const increasedByOne = [];
32
numbers.forEach((num) => {
33
increasedByOne.push(num + 1);
34
});
35
36
// best (keeping it functional)
37
38
const increasedByOne = numbers.map((num) => num + 1);
Copied!

--> 11.2 Don't use generators for now.

1
> Why? They don't transpile well to ES5.
Copied!
  • 11.3 If you must use generators, or if you disregard our advice, make sure their function signature is spaced properly. eslint: [generator-star-spacing](https: //eslint.org/docs/rules/generator-star-spacing)
    Why? function and * are part of the same conceptual keyword - * is not a modifier for function, function* is a unique construct, different from function.
1
// bad
2
function* foo() {
3
// ...
4
}
5
6
// bad
7
8
const bar = function* () {
9
// ...
10
};
11
12
// bad
13
14
const baz = function* () {
15
// ...
16
};
17
18
// bad
19
20
const quux = function* () {
21
// ...
22
};
23
24
// bad
25
function* foo() {
26
// ...
27
}
28
29
// bad
30
function* foo() {
31
// ...
32
}
33
34
// very bad
35
function* foo() {
36
// ...
37
}
38
39
// very bad
40
41
const wat = function* () {
42
// ...
43
};
44
45
// good
46
function* foo() {
47
// ...
48
}
49
50
// good
51
52
const foo = function* () {
53
// ...
54
};
Copied!

Properties

  • 12.1 Use dot notation when accessing properties. eslint: [dot-notation](https: //eslint.org/docs/rules/dot-notation.html)
1
const luke = {
2
jedi: true,
3
age: 28,
4
};
5
6
// bad
7
8
const isJedi = luke["jedi"];
9
10
// good
11
12
const isJedi = luke.jedi;
Copied!

--> 12.2 Use bracket notation [] when accessing properties with a variable.

1
const luke = {
2
jedi: true,
3
age: 28,
4
};
5
6
function getProp(prop) {
7
return luke[prop];
8
}
9
10
const isJedi = getProp("jedi");
Copied!

--> 12.3 Use exponentiation operator ** when calculating exponentiations. eslint: [no-restricted-properties](https:

//eslint.org/docs/rules/no-restricted-properties).
1
// bad
2
3
const binary = Math.pow(2, 10);
4
5
// good
6
7
const binary = 2 ** 10;
Copied!

Variables

  • 13.1 Always use const or let to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [no-undef](https: //eslint.org/docs/rules/no-undef) [prefer- const](https: //eslint.org/docs/rules/prefer- const)
1
// bad
2
superPower = new SuperPower();
3
4
// good
5
6
const superPower = new SuperPower();
Copied!

--> 13.2 Use one `

constorlet declaration per variable or assignment. eslint: [one-var`](https: //eslint.org/docs/rules/one-var.html)
1
> Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once.
Copied!
1
// bad
2
3
const items = getItems(),
4
goSportsTeam = true,
5
dragonball = "z";
6
7
// bad
8
9
// (compare to above, and try to spot the mistake)
10
11
const items = getItems(),
12
goSportsTeam = true;
13
dragonball = "z";
14
15
// good
16
17
const items = getItems();
18
19
const goSportsTeam = true;
20
21
const dragonball = "z";
Copied!

--> 13.3 Group all your `

consts and then group all your let`s.
1
> Why? This is helpful when later on you might need to assign a variable depending on one of the previously assigned variables.
Copied!
1
// bad
2
let i,
3
len,
4
dragonball,
5
items = getItems(),
6
goSportsTeam = true;
7
8
// bad
9
let i;
10
11
const items = getItems();
12
let dragonball;
13
14
const goSportsTeam = true;
15
let len;
16
17
// good
18
19
const goSportsTeam = true;
20
21
const items = getItems();
22
let dragonball;
23
let i;
24
let length;
Copied!

--> 13.4 Assign variables where you need them, but place them in a reasonable place.

1
> Why? `let` and `
2
const` are block scoped and not function scoped.
Copied!
1
// bad - unnecessary function call
2
function checkName(hasName) {
3
const name = getName();
4
5
if (hasName === "test") {
6
return false;
7
}
8
9
if (name === "test") {
10
this.setName("");
11
return false;
12
}
13
14
return name;
15
}
16
17
// good
18
function checkName(hasName) {
19
if (hasName === "test") {
20
return false;
21
}
22
23
const name = getName();
24
25
if (name === "test") {
26
this.setName("");
27
return false;
28
}
29
30
return name;
31
}
Copied!

--> 13.5 Don't chain variable assignments. eslint: [no-multi-assign](https:

//eslint.org/docs/rules/no-multi-assign)
1
> Why? Chaining variable assignments creates implicit global variables.
Copied!
1
// bad
2
(function example() {
3
4
// JavaScript interprets this as
5
6
// let a = ( b = ( c = 1 ) );
7
8
// The let keyword only applies to variable a; variables b and c become
9
10
// global variables.
11
let a = (b = c = 1);
12
})();
13
14
console.log(a);
15
// throws ReferenceError
16
console.log(b);
17
// 1
18
console.log(c);
19
// 1
20
21
22
// good
23
(function example() {
24
let a = 1;
25
let b = a;
26
let c = a;
27
})();
28
29
console.log(a);
30
// throws ReferenceError
31
console.log(b);
32
// throws ReferenceError
33
console.log(c);
34
// throws ReferenceError
35
36
37
// the same applies for `
38
const`
Copied!

--> 13.6 Avoid using unary increments and decrements (++, --). eslint [no-plusplus](https:

//eslint.org/docs/rules/no-plusplus)
1
> Why? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with incrementing or decrementing values within an application. It is also more expressive to mutate your values with statements like `num += 1` instead of `num++` or `num ++`. Disallowing unary increment and decrement statements also prevents you from pre-incrementing/pre-decrementing values unintentionally which can also cause unexpected behavior in your programs.
Copied!
1
// bad
2
3
const array = [1, 2, 3];
4
let num = 1;
5
num++;
6
--num;
7
8
let sum = 0;
9
let truthyCount = 0;
10
for (let i = 0; i < array.length; i++) {
11
let value = array[i];
12
sum += value;
13
if (value) {
14
truthyCount++;
15
}
16
}
17
18
// good
19
20
const array = [1, 2, 3];
21
let num = 1;
22
num += 1;
23
num -= 1;
24
25
const sum = array.reduce((a, b) => a + b, 0);
26
27
const truthyCount = array.filter(Boolean).length;
Copied!

--> 13.7 Avoid linebreaks before or after = in an assignment. If your assignment violates [max-len](https:

//eslint.org/docs/rules/max-len.html), surround the value in parens. eslint [operator-linebreak](https: //eslint.org/docs/rules/operator-linebreak.html).
1
> Why? Linebreaks surrounding `=` can obfuscate the value of an assignment.
Copied!
1
// bad
2
3
const foo = superLongLongLongLongLongLongLongLongFunctionName();
4
5
// bad
6
7
const foo = "superLongLongLongLongLongLongLongLongString";
8
9
// good
10
11
const foo = superLongLongLongLongLongLongLongLongFunctionName();
12
13
// good
14
15
const foo = "superLongLongLongLongLongLongLongLongString";
Copied!

--> 13.8 Disallow unused variables. eslint: [no-unused-vars](https:

//eslint.org/docs/rules/no-unused-vars)
1
> Why? Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers.
Copied!
1
// bad
2
3
var some_unused_var = 42;
4
5
// Write-only variables are not considered as used.
6
var y = 10;
7
y = 5;
8
9
// A read for a modification of itself is not considered as used.
10
var z = 0;
11
z = z + 1;
12
13
// Unused function arguments.
14
function getX(x, y) {
15
return x;
16
}
17
18
// good
19
20
function getXPlusY(x, y) {
21
return x + y;
22
}
23
24
var x = 1;
25
var y = a + 2;
26
27
alert(getXPlusY(x, y));
28
29
// 'type' is ignored even if unused because it has a rest property sibling.
30
31
// This is a form of extracting an object that omits the specified keys.
32
var { type, ...coords } = data;
33
34
// 'coords' is now the 'data' object without its 'type' property.
Copied!

Hoisting

  • 14.1 var declarations get hoisted to the top of their closest enclosing function scope, their assignment does not. const and let declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). It's important to know why [typeof is no longer safe](https: //web.archive.org/web/20200121061528/http: //es-discourse.com/t/why-typeof-is-no-longer-safe/15).
1
// we know this wouldn't work (assuming there
2
3
// is no notDefined global variable)
4
function example() {
5
console.log(notDefined);
6
// => throws a ReferenceError
7
}
8
9
10
// creating a variable declaration after you
11
12
// reference the variable will work due to
13
14
// variable hoisting. Note: the assignment
15
16
// value of `true` is not hoisted.
17
function example() {
18
console.log(declaredButNotAssigned);
19
// => undefined
20
var declaredButNotAssigned = true;
21
}
22
23
24
// the interpreter is hoisting the variable
25
26
// declaration to the top of the scope,
27
28
// which means our example could be rewritten as:
29
function example() {
30
let declaredButNotAssigned;
31
console.log(declaredButNotAssigned);
32
// => undefined
33
declaredButNotAssigned = true;
34
}
35
36
37
// using
38
const and let
39
function example() {
40
console.log(declaredButNotAssigned);
41
// => throws a ReferenceError
42
console.log(typeof declaredButNotAssigned);
43
// => throws a ReferenceError
44
45
const declaredButNotAssigned = true;
46
}
Copied!

--> 14.2 Anonymous function expressions hoist their variable name, but not the function assignment.

1
function example() {
2
console.log(anonymous);
3
// => undefined
4
5
anonymous();
6
// => TypeError anonymous is not a function
7
8
var anonymous = function () {
9
console.log("anonymous function expression");
10
};
11
}
Copied!

--> 14.3 Named function expressions hoist the variable name, not the function name or the function body.

1
function example() {
2
console.log(named);
3
// => undefined
4
5
named();
6
// => TypeError named is not a function
7
8
superPower();
9
// => ReferenceError superPower is not defined
10
11
var named = function superPower() {
12
console.log("Flying");
13
};
14
}
15
16
// the same is true when the function name
17
18
// is the same as the variable name.
19
function example() {
20
console.log(named);
21
// => undefined
22
23
named();
24
// => TypeError named is not a function
25
26
var named = function named() {
27
console.log("named");
28
};
29
}
Copied!

--> 14.4 Function declarations hoist their name and the function body.

1
function example() {
2
superPower();
3
// => Flying
4
5
function superPower() {
6
console.log("Flying");
7
}
8
}
Copied!

--> For more information refer to [JavaScript Scoping & Hoisting](https:

//www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](https: //www.adequatelygood.com).

Comparison Operators & Equality

  • 15.1 Use === and !== over == and !=. eslint: [eqeqeq](https: //eslint.org/docs/rules/eqeqeq.html)
  • 15.2 Conditional statements such as the if statement evaluate their expression using coercion with the ToBoolean abstract method and always follow these simple rules:
    • Objects evaluate to true
    • Undefined evaluates to false
    • Null evaluates to false
    • Booleans evaluate to the value of the boolean
    • Numbers evaluate to false if +0, -0, or NaN, otherwise true
    • Strings evaluate to false if an empty string '', otherwise true
1
if ([0] && []) {
2
// true
3
// an array (even an empty one) is an object, objects will evaluate to true
4
}
Copied!

--> 15.3 Use shortcuts for booleans, but explicit comparisons for strings and numbers.

1
// bad
2
if (isValid === true) {
3
// ...
4
}
5
6
// good
7
if (isValid) {
8
// ...
9
}
10
11
// bad
12
if (name) {
13
// ...
14
}
15
16
// good
17
if (name !== "") {
18
// ...
19
}
20
21
// bad
22
if (collection.length) {
23
// ...
24
}
25
26
// good
27
if (collection.length > 0) {
28
// ...
29
}
Copied!

--> 15.4 For more information see [Truth Equality and JavaScript](https:

//javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
  • 15.5 Use braces to create blocks in case and default clauses that contain lexical declarations (e.g. let, const, function, and class). eslint: [no-case-declarations](https: //eslint.org/docs/rules/no-case-declarations.html)
    Why? Lexical declarations are visible in the entire switch block but only get initialized when assigned, which only happens when its case is reached. This causes problems when multiple case clauses attempt to define the same thing.
1
// bad
2
switch (foo) {
3
case 1:
4
let x = 1;
5
break;
6
case 2:
7
const y = 2;
8
break;
9
case 3:
10
function f() {
11
// ...
12
}
13
break;
14
default:
15
class C {}
16
}
17
18
// good
19
switch (foo) {
20
case 1: {
21
let x = 1;
22
break;
23
}
24
case 2: {
25
const y = 2;
26
break;
27
}
28
case 3: {
29
function f() {
30
// ...
31
}
32
break;
33
}
34
case 4:
35
bar();
36
break;
37
default: {
38
class C {}
39
}
40
}
Copied!

--> 15.6 Ternaries should not be nested and generally be single line expressions. eslint: [no-nested-ternary](https:

//eslint.org/docs/rules/no-nested-ternary.html)
1
// bad
2
3
const foo = maybe1 > maybe2 ? "bar" : value1 > value2 ? "baz" : null;
4
5
// split into 2 separated ternary expressions
6
7
const maybeNull = value1 > value2 ? "baz" : null;
8
9
// better
10
11
const foo = maybe1 > maybe2 ? "bar" : maybeNull;
12
13
// best
14
15
const foo = maybe1 > maybe2 ? "bar" : maybeNull;
Copied!

--> 15.7 Avoid unneeded ternary statements. eslint: [no-unneeded-ternary](https:

//eslint.org/docs/rules/no-unneeded-ternary.html)
1
// bad
2
3
const foo = a ? a : b;
4
5
const bar = c ? true : false;
6
7
const baz = c ? false : true;
8
9
// good
10
11
const foo = a || b;
12
13
const bar = !!c;
14
15
const baz = !c;
Copied!

--> 15.8 When mixing operators, enclose them in parentheses. The only exception is the standard arithmetic operators: +, -, and ** since their precedence is broadly understood. We recommend enclosing / and * in parentheses because their precedence can be ambiguous when they are mixed. eslint: [no-mixed-operators](https:

//eslint.org/docs/rules/no-mixed-operators.html)
1
> Why? This improves readability and clarifies the developer's intention.
Copied!
1
// bad
2
3
const foo = (a && b < 0) || c > 0 || d + 1 === 0;
4
5
// bad
6
7
const bar = a ** b - (5 % d);
8
9
// bad
10
11
// one may be confused into thinking (a || b) && c
12
if (a || (b && c)) {
13
return d;
14
}
15
16
// bad
17
18
const bar = a + (b / c) * d;
19
20
// good
21
22
const foo = (a && b < 0) || c > 0 || d + 1 === 0;
23
24
// good
25
26
const bar = a ** b - (5 % d);
27
28
// good
29
if (a || (b && c)) {
30
return d;
31
}
32
33
// good
34
35
const bar = a + (b / c) * d;
Copied!

Blocks

  • 16.1 Use braces with all multiline blocks. eslint: [nonblock-statement-body-position](https: //eslint.org/docs/rules/nonblock-statement-body-position)
1
// bad
2
if (test) return false;
3
4
// good
5
if (test) return false;
6
7
// good
8
if (test) {
9
return false;
10
}
11
12
// bad
13
function foo() {
14
return false;
15
}
16
17
// good
18
function bar() {
19
return false;
20
}
Copied!

--> 16.2 If you're using multiline blocks with if and else, put else on the same line as your if block's closing brace. eslint: [brace-style](https:

//eslint.org/docs/rules/brace-style.html)
1
// bad
2
if (test) {
3
thing1();
4
thing2();
5
} else {
6
thing3();
7
}
8
9
// good
10
if (test) {
11
thing1();
12
thing2();
13
} else {
14
thing3();
15
}
Copied!

--> 16.3 If an if block always executes a return statement, the subsequent else block is unnecessary. A return in an else if block following an if block that contains a return can be separated into multiple if blocks. eslint: [no-else-return](https:

//eslint.org/docs/rules/no-else-return)
1
// bad
2
function foo() {
3
if (x) {
4
return x;
5
} else {
6
return y;
7
}
8
}
9
10
// bad
11
function cats() {
12
if (x) {
13
return x;
14
} else if (y) {
15
return y;
16
}
17
}
18
19
// bad
20
function dogs() {
21
if (x) {
22
return x;
23
} else {
24
if (y) {
25
return y;
26
}
27
}
28
}
29
30
// good
31
function foo() {
32
if (x) {
33
return x;
34
}
35
36
return y;
37
}
38
39
// good
40
function cats() {
41
if (x) {
42
return x;
43
}
44
45
if (y) {
46
return y;
47
}
48
}
49
50
// good
51
function dogs(x) {
52
if (x) {
53
if (z) {
54
return y;
55
}
56
} else {
57
return z;
58
}
59
}
Copied!

Control Statements

  • 17.1 In case your control statement (if, while etc.) gets too long or exceeds the maximum line length, each (grouped) condition could be put into a new line. The logical operator should begin the line.
    Why? Requiring operators at the beginning of the line keeps the operators aligned and follows a pattern similar to method chaining. This also improves readability by making it easier to visually follow complex logic.
1
// bad
2
if (
3
(foo === 123 || bar === "abc") &&
4
doesItLookGoodWhenItBecomesThatLong() &&
5
isThisReallyHappening()
6
) {
7
thing1();
8
}
9
10
// bad
11
if (foo === 123 && bar === "abc") {
12
thing1();
13
}
14
15
// bad
16
if (foo === 123 && bar === "abc") {
17
thing1();
18
}
19
20
// bad
21
if (foo === 123 && bar === "abc") {
22
thing1();
23
}
24
25
// good
26
if (foo === 123 && bar === "abc") {
27
thing1();
28
}
29
30
// good
31
if (
32
(foo === 123 || bar === "abc") &&
33
doesItLookGoodWhenItBecomesThatLong() &&
34
isThisReallyHappening()
35
) {
36
thing1();
37
}
38
39
// good
40
if (foo === 123 && bar === "abc") {
41
thing1();
42
}
Copied!

--> 17.2 Don't use selection operators in place of control statements.

1
// bad
2
!isRunning && startRunning();
3
4
// good
5
if (!isRunning) {
6
startRunning();
7
}
Copied!

Comments

  • 18.1 Use /** ... */ for multiline comments.
1
// bad
2
3
// make() returns a new element
4
5
// based on the passed in tag name
6
7
//
8
9
// @param {String} tag
10
11
// @return {Element} element
12
function make(tag) {
13
// ...
14
15
return element;
16
}
17
18
// good
19
/**
20
* make() returns a new element
21
* based on the passed-in tag name
22
*/
23
function make(tag) {
24
// ...
25
26
return element;
27
}
Copied!

--> 18.2 Use `

//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block.
1
// bad
2
3
const active = true;
4
// is current tab
5
6
// good
7
8
// is current tab
9
10
const active = true;
11
12
// bad
13
function getType() {
14
console.log("fetching type...");
15
16
// set the default type to 'no type'
17
18
const type = this.type || "no type";
19
20
return type;
21
}
22
23
// good
24
function getType() {
25
console.log("fetching type...");
26
27
// set the default type to 'no type'
28
29
const type = this.type || "no type";
30
31
return type;
32
}
33
34
// also good
35
function getType() {
36
// set the default type to 'no type'
37
38
const type = this.type || "no type";
39
40
return type;
41
}
Copied!

--> 18.3 Start all comments with a space to make it easier to read. eslint: [spaced-comment](https:

//eslint.org/docs/rules/spaced-comment)
1
// bad
2
3
//is current tab
4
5
const active = true;
6
7
// good
8
9
// is current tab
10
11
const active = true;
12
13
// bad
14
/**
15
*make() returns a new element
16
*based on the passed-in tag name
17
*/
18
function make(tag) {
19
// ...
20
21
return element;
22
}
23
24
// good
25
/**
26
* make() returns a new element
27
* based on the passed-in tag name
28
*/
29
function make(tag) {
30
// ...
31
32
return element;
33
}
Copied!

--> 18.4 Prefixing your comments with FIXME or TODO helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are FIXME: -- need to figure this out or TODO: -- need to implement.

  • 18.5 Use // FIXME: to annotate problems.
1
class Calculator extends Abacus {
2
constructor() {
3
super();
4
5
// FIXME: shouldn't use a global here
6
total = 0;
7
}
8
}
Copied!

--> 18.6 Use `

// TODO:` to annotate solutions to problems.
1
class Calculator extends Abacus {
2
constructor() {
3
super();
4
5
// TODO: total should be configurable by an options param
6
this.total = 0;
7
}
8
}
Copied!

Whitespace

  • 19.1 Use soft tabs (space character) set to 2 spaces. eslint: [indent](https: //eslint.org/docs/rules/indent.html)
1
// bad
2
function foo() {
3
∙∙∙∙let name;
4
}
5
6
7
// bad
8
function bar() {
9
∙let name;
10
}
11
12
13
// good
14
function baz() {
15
∙∙let name;
16
}
Copied!

--> 19.2 Place 1 space before the leading brace. eslint: [space-before-blocks](https:

//eslint.org/docs/rules/space-before-blocks.html)
1
// bad
2
function test() {
3
console.log("test");
4
}
5
6
// good
7
function test() {
8
console.log("test");
9
}
10
11
// bad
12
dog.set("attr", {
13
age: "1 year",
14
breed: "Bernese Mountain Dog",
15
});
16
17
// good
18
dog.set("attr", {
19
age: "1 year",
20
breed: "Bernese Mountain Dog",
21
});
Copied!

--> 19.3 Place 1 space before the opening parenthesis in control statements (if, while etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [keyword-spacing](https:

//eslint.org/docs/rules/keyword-spacing.html)
1
// bad
2
if (isJedi) {
3
fight();
4
}
5
6
// good
7
if (isJedi) {
8
fight();
9
}
10
11
// bad
12
function fight() {
13
console.log("Swooosh!");
14
}
15
16
// good
17
function fight() {
18
console.log("Swooosh!");
19
}
Copied!

--> 19.4 Set off operators with spaces. eslint: [space-infix-ops](https:

//eslint.org/docs/rules/space-infix-ops.html)
1
// bad
2
3
const x = y + 5;
4
5
// good
6
7
const x = y + 5;
Copied!

--> 19.5 End files with a single newline character. eslint: [eol-last](https:

//github.com/eslint/eslint/blob/master/docs/rules/eol-last.md)
1
// bad
2
import { es6 } from "./AirbnbStyleGuide";
3
4
// ...
5
export default es6;
Copied!
1
// bad
2
import { es6 } from './AirbnbStyleGuide';
3
4
// ...
5
export default es6;↵
6
Copied!
1
// good
2
import { es6 } from './AirbnbStyleGuide';
3
4
// ...
5
export default es6;↵
Copied!

--> 19.6 Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](https:

//eslint.org/docs/rules/newline-per-chained-call) [no-whitespace-before-property](https: //eslint.org/docs/rules/no-whitespace-before-property)
1
// bad
2
$("#items").find(".selected").highlight().end().find(".open").updateCount();
3
4
// bad
5
$("#items").find(".selected").highlight().end().find(".open").updateCount();
6
7
// good
8
$("#items").find(".selected").highlight().end().find(".open").updateCount();
9
10
// bad
11
12
const leds = stage
13
.selectAll(".led")
14
.data(data)
15
.enter()
16
.append("svg:svg")
17
.classed("led", true)
18
.attr("width", (radius + margin) * 2)
19
.append("svg:g")
20
.attr("transform", `translate(${radius + margin},${radius + margin})`)
21
.call(tron.led);
22
23
// good
24
25
const leds = stage
26
.selectAll(".led")
27
.data(data)
28
.enter()
29
.append("svg:svg")
30
.classed("led", true)
31
.attr("width", (radius + margin) * 2)
32
.append("svg:g")
33
.attr("transform", `translate(${radius + margin},${radius + margin})`)
34
.call(tron.led);
35
36
// good
37
38
const leds = stage.selectAll(".led").data(data);
39
40
const svg = leds.enter().append("svg:svg");
41
svg.classed("led", true).attr("width", (radius + margin) * 2);
42
43
const g = svg.append("svg:g");
44
g.attr("transform", `translate(${radius + margin},${radius + margin})`).call(
45
tron.led
46
);
Copied!

--> 19.7 Leave a blank line after blocks and before the next statement.

1
// bad
2
if (foo) {
3
return bar;
4
}
5
return baz;
6
7
// good
8
if (foo) {
9
return bar;
10
}
11
12
return baz;
13
14
// bad
15
16
const obj = {
17
foo() {},
18
bar() {},
19
};
20
return obj;
21
22
// good
23
24
const obj = {
25
foo() {},
26
27
bar() {},
28
};
29
30
return obj;
31
32
// bad
33
34
const arr = [function foo() {}, function bar() {}];
35
return arr;
36
37
// good
38
39
const arr = [function foo() {}, function bar() {}];
40
41
return arr;
Copied!

--> 19.8 Do not pad your blocks with blank lines. eslint: [padded-blocks](https:

//eslint.org/docs/rules/padded-blocks.html)
1
// bad
2
function bar() {
3
console.log(foo);
4
}
5
6
// bad
7
if (baz) {
8
console.log(qux);
9
} else {
10
console.log(foo);
11
}
12
13
// bad
14
class Foo {
15
constructor(bar) {
16
this.bar = bar;
17
}
18
}
19
20
// good
21
function bar() {
22
console.log(foo);
23
}
24
25
// good
26
if (baz) {
27
console.log(qux);
28
} else {
29
console.log(foo);
30
}
Copied!

--> 19.9 Do not use multiple blank lines to pad your code. eslint: [no-multiple-empty-lines](https:

//eslint.org/docs/rules/no-multiple-empty-lines)
1
// bad
2
class Person {
3
constructor(fullName, email, birthday) {
4
this.fullName = fullName;
5
6
this.email = email;
7
8
this.setAge(birthday);
9
}
10
11
setAge(birthday) {
12
const today = new Date();
13
14
const age = this.getAge(today, birthday);
15
16
this.age = age;
17
}
18
19
getAge(today, birthday) {
20
// ..
21
}
22
}
23
24
// good
25
class Person {
26
constructor(fullName, email, birthday) {
27
this.fullName = fullName;
28
this.email = email;
29
this.setAge(birthday);
30
}
31
32
setAge(birthday) {
33
const today = new Date();
34
35
const age = getAge(today, birthday);
36
this.age = age;
37
}
38
39
getAge(today, birthday) {
40
// ..
41
}
42
}
Copied!

--> 19.10 Do not add spaces inside parentheses. eslint: [space-in-parens](https:

//eslint.org/docs/rules/space-in-parens.html)
1
// bad
2
function bar(foo) {
3
return foo;
4
}
5
6
// good
7
function bar(foo) {
8
return foo;
9
}
10
11
// bad
12
if (foo) {
13
console.log(foo);
14
}
15
16
// good
17
if (foo) {
18
console.log(foo);
19
}
Copied!

--> 19.11 Do not add spaces inside brackets. eslint: [array-bracket-spacing](https:

//eslint.org/docs/rules/array-bracket-spacing.html)
1
// bad
2
3
const foo = [1, 2, 3];
4
console.log(foo[0]);
5
6
// good
7
8
const foo = [1, 2, 3];
9
console.log(foo[0]);
Copied!

--> 19.12 Add spaces inside curly braces. eslint: [object-curly-spacing](https:

//eslint.org/docs/rules/object-curly-spacing.html)
1
// bad
2
3
const foo = { clark: "kent" };
4
5
// good
6
7
const foo = { clark: "kent" };
Copied!

--> 19.13 Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per above, long strings are exempt from this rule, and should not be broken up. eslint: [max-len](https:

//eslint.org/docs/rules/max-len.html)
1
> Why? This ensures readability and maintainability.
Copied!
1
// bad
2
3
const foo =
4
jsonData &&
5
jsonData.foo &&
6
jsonData.foo.bar &&
7
jsonData.foo.bar.baz &&
8
jsonData.foo.bar.baz.quux &&
9
jsonData.foo.bar.baz.quux.xyzzy;
10
11
12
// bad
13
$.ajax({ method: "POST", url: "https:
14
//airbnb.com/", data: { name: "John" } })
15
.done(() => console.log("Congratulations!"))
16
.fail(() => console.log("You have failed this city."));
17
18
19
// good
20
21
const foo =
22
jsonData &&
23
jsonData.foo &&
24
jsonData.foo.bar &&
25
jsonData.foo.bar.baz &&
26
jsonData.foo.bar.baz.quux &&
27
jsonData.foo.bar.baz.quux.xyzzy;
28
29
30
// good
31
$.ajax({
32
method: "POST",
33
url: "https:
34
//airbnb.com/",
35
data: { name: "John" },
36
})
37
.done(() => console.log("Congratulations!"))
38
.fail(() => console.log("You have failed this city."));
Copied!

--> 19.14 Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. eslint: [block-spacing](https:

//eslint.org/docs/rules/block-spacing)
1
// bad
2
function foo() {
3
return true;
4
}
5
if (foo) {
6
bar = 0;
7
}
8
9
// good
10
function foo() {
11
return true;
12
}
13
if (foo) {
14
bar = 0;
15
}
Copied!

--> 19.15 Avoid spaces before commas and require a space after commas. eslint: [comma-spacing](https:

//eslint.org/docs/rules/comma-spacing)
1
// bad
2
var foo = 1,
3
bar = 2;
4
var arr = [1, 2];
5
6
// good
7
var foo = 1,
8
bar = 2;
9
var arr = [1, 2];
Copied!

--> 19.16 Enforce spacing inside of computed property brackets. eslint: [computed-property-spacing](https:

//eslint.org/docs/rules/computed-property-spacing)
1
// bad
2
obj[foo];
3
obj["foo"];
4
var x = { [b]: a };
5
obj[foo[bar]];
6
7
// good
8
obj[foo];
9
obj["foo"];
10
var x = { [b]: a };
11
obj[foo[bar]];
Copied!

--> 19.17 Avoid spaces between functions and their invocations. eslint: [func-call-spacing](https:

//eslint.org/docs/rules/func-call-spacing)
1
// bad
2
func();
3
4
func();
5
6
// good
7
func();
Copied!

--> 19.18 Enforce spacing between keys and values in object literal properties. eslint: [key-spacing](https:

//eslint.org/docs/rules/key-spacing)
1
// bad
2
var obj = { foo: 42 };
3
var obj2 = { foo: 42 };
4
5
// good
6
var obj = { foo: 42 };
Copied!

--> 19.19 Avoid trailing spaces at the end of lines. eslint: [no-trailing-spaces](https:

//eslint.org/docs/rules/no-trailing-spaces)
  • 19.20 Avoid multiple empty lines, only allow one newline at the end of files, and avoid a newline at the beginning of files. eslint: [no-multiple-empty-lines](https: //eslint.org/docs/rules/no-multiple-empty-lines)
1
// bad - multiple empty lines
2
var x = 1;
3
4
var y = 2;
5
6
// bad - 2+ newlines at end of file
7
var x = 1;
8
var y = 2;
9
10
// bad - 1+ newline(s) at beginning of file
11
12
var x = 1;
13
var y = 2;
14
15
// good
16
var x = 1;
17
var y = 2;
Copied!

Commas

  • 20.1 Leading commas: Nope. eslint: [comma-style](https: //eslint.org/docs/rules/comma-style.html)
1
// bad
2
3
const story = [once, upon, aTime];
4
5
// good
6
7
const story = [once, upon, aTime];
8
9
// bad
10
11
const hero = {
12
firstName: "Ada",
13
lastName: "Lovelace",
14
birthYear: 1815,
15
superPower: "computers",
16
};
17
18
// good
19
20
const hero = {
21
firstName: "Ada",
22
lastName: "Lovelace",
23
birthYear: 1815,
24
superPower: "computers",
25
};
Copied!

--> 20.2 Additional trailing comma: Yup. eslint: [comma-dangle](https:

//eslint.org/docs/rules/comma-dangle.html)
1
> Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](https:
2
//github.com/airbnb/javascript/blob/es5-deprecated/es5/README.md#commas) in legacy browsers.
Copied!
1
diff
2
3
// bad - git diff without trailing comma
4
5
const hero = {
6
firstName: 'Florence',
7
- lastName: 'Nightingale'
8
+ lastName: 'Nightingale',
9
+ inventorOf: ['coxcomb chart', 'modern nursing']
10
};
11
12
13
// good - git diff with trailing comma
14
15
const hero = {
16
firstName: 'Florence',
17
lastName: 'Nightingale',
18
+ inventorOf: ['coxcomb chart', 'modern nursing'],
19
};
Copied!
1
// bad
2
3
const hero = {
4
firstName: "Dana",
5
lastName: "Scully",
6
};
7
8
const heroes = ["Batman", "Superman"];
9
10
// good
11
12
const hero = {
13
firstName: "Dana",
14
lastName: "Scully",
15
};
16
17
const heroes = ["Batman", "Superman"];
18
19
// bad
20
function createHero(firstName, lastName, inventorOf) {
21
// does nothing
22
}
23
24
// good
25
function createHero(firstName, lastName, inventorOf) {
26
// does nothing
27
}
28
29
// good (note that a comma must not appear after a "rest" element)
30
function createHero(firstName, lastName, inventorOf, ...heroArgs) {
31
// does nothing
32
}
33
34
// bad
35
createHero(firstName, lastName, inventorOf);
36
37
// good
38
createHero(firstName, lastName, inventorOf);
39
40
// good (note that a comma must not appear after a "rest" element)
41
createHero(firstName, lastName, inventorOf, ...heroArgs);
Copied!

Semicolons

  • 21.1 Yup. eslint: [semi](https: //eslint.org/docs/rules/semi.html)
    Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called [Automatic Semicolon Insertion](https: //tc39.github.io/ecma262/#sec-automatic-semicolon-insertion) to determine whether it should regard that line break as the end of a statement, and (as the name implies) place a semicolon into your code before the line break if it thinks so. ASI contains a few eccentric behaviors, though, and your code will break if JavaScript misinterprets your line break. These rules will become more complicated as new features become a part of JavaScript. Explicitly terminating your statements and configuring your linter to catch missing semicolons will help prevent you from encountering issues.
1
// bad - raises exception
2
3
const luke = {};
4
5
const leia = {}[(luke, leia)].forEach((jedi) => (jedi.father = "vader"));
6
7
// bad - raises exception
8
9
const reaction = "No! That's impossible!"(
10
(async function meanwhileOnTheFalcon() {
11
// handle `leia`, `lando`, `chewie`, `r2`, `c3p0`
12
// ...
13
})()
14
);
15
16
// bad - returns `undefined` instead of the value on the next line - always happens when `return` is on a line by itself because of ASI!
17
function foo() {
18
return;
19
("search your feelings, you know it to be foo");
20
}
21
22
// good
23
24
const luke = {};
25
26
const leia = {};
27
[luke, leia].forEach((jedi) => {
28
jedi.father = "vader";
29
});
30
31
// good
32
33
const reaction = "No! That's impossible!";
34
(async function meanwhileOnTheFalcon() {
35
// handle `leia`, `lando`, `chewie`, `r2`, `c3p0`
36
// ...
37
})();
38
39
// good
40
function foo() {
41
return "search your feelings, you know it to be foo";
42
}
Copied!
1
[Read more](https:
2
//stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214#7365214).
Copied!

Type Casting & Coercion

  • 22.1 Perform type coercion at the beginning of the statement.
  • 22.2 Strings: eslint: [no-new-wrappers](https: //eslint.org/docs/rules/no-new-wrappers)
1
// => this.reviewScore = 9;
2
3
// bad
4
5
const totalScore = new String(this.reviewScore);
6
// typeof totalScore is "object" not "string"
7
8
// bad
9
10
const totalScore = this.reviewScore + "";
11
// invokes this.reviewScore.valueOf()
12
13
// bad
14
15
const totalScore = this.reviewScore.toString();
16
// isn't guaranteed to return a string
17
18
// good
19
20
const totalScore = String(this.reviewScore);
Copied!

--> 22.3 Numbers: Use Number for type casting and parseInt always with a radix for parsing strings. eslint: [radix](https:

//eslint.org/docs/rules/radix) [no-new-wrappers](https: //eslint.org/docs/rules/no-new-wrappers)
1
> Why? The `parseInt` function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading whitespace in string is ignored. If radix is `undefined` or `0`, it is assumed to be `10` except when the number begins with the character pairs `0x` or `0X`, in which case a radix of 16 is assumed. This differs from ECMAScript 3, which merely discouraged (but allowed) octal interpretation. Many implementations have not adopted this behavior as of 2013. And, because older browsers must be supported, always specify a radix.
Copied!
1
const inputValue = "4";
2
3
// bad
4
5
const val = new Number(inputValue);
6
7
// bad
8
9
const val = +inputValue;
10
11
// bad
12
13
const val = inputValue >> 0;
14
15
// bad
16
17
const val = parseInt(inputValue);
18
19
// good
20
21
const val = Number(inputValue);
22
23
// good
24
25
const val = parseInt(inputValue, 10);
Copied!

--> 22.4 If for whatever reason you are doing something wild and parseInt is your bottleneck and need to use Bitshift for [performance reasons](https:

//jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing.
1
// good
2
/**
3
* parseInt was the reason my code was slow.
4
* Bitshifting the String to coerce it to a
5
* Number made it a lot faster.
6
*/
7
8
const val = inputValue >> 0;
Copied!

--> 22.5 Note: Be careful when using bitshift operations. Numbers are represented as [64-bit values](https:

//es5.github.io/#x4.3.19), but bitshift operations always return a 32-bit integer ([source](https: //es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https: //github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647:
1
2147483647 >> 0;
2
// => 2147483647
3
2147483648 >> 0;
4
// => -2147483648
5
2147483649 >> 0;
6
// => -2147483647
Copied!

--> 22.6 Booleans: eslint: [no-new-wrappers](https:

//eslint.org/docs/rules/no-new-wrappers)
1
const age = 0;
2
3
// bad
4
5
const hasAge = new Boolean(age);
6
7
// good
8
9
const hasAge = Boolean(age);
10
11
// best
12
13
const hasAge = !!age;
Copied!

Naming Conventions

  • 23.1 Avoid single letter names. Be descriptive with your naming. eslint: [id-length](https: //eslint.org/docs/rules/id-length)
1
// bad
2
function q() {
3
// ...
4
}
5
6
// good
7
function query() {
8
// ...
9
}
Copied!

--> 23.2 Use camelCase when naming objects, functions, and instances. eslint: [camelcase](https:

//eslint.org/docs/rules/camelcase.html)
1
// bad
2
3
const OBJEcttsssss = {};
4
5
const this_is_my_object = {};
6
function c() {}
7
8
// good
9
10
const thisIsMyObject = {};
11
function thisIsMyFunction() {}
Copied!

--> 23.3 Use PascalCase only when naming

constructors or classes. eslint: [new-cap](https: //eslint.org/docs/rules/new-cap.html)
1
// bad
2
function user(options) {
3
this.name = options.name;
4
}
5
6
const bad = new user({
7
name: "nope",
8
});
9
10
// good
11
class User {
12
constructor(options) {
13
this.name = options.name;
14
}
15
}
16
17
const good = new User({
18
name: "yup",
19
});
Copied!

--> 23.4 Do not use trailing or leading underscores. eslint: [no-underscore-dangle](https:

//eslint.org/docs/rules/no-underscore-dangle.html)
1
> Why? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean "private", in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won't count as breaking, or that tests aren't needed. tl;dr: if you want something to be "private", it must not be observably present.
Copied!
1
// bad
2
this.__firstName__ = "Panda";
3
this.firstName_ = "Panda";
4
this._firstName = "Panda";
5
6
// good
7
this.firstName = "Panda";
8
9
// good, in environments where WeakMaps are available
10
11
// see https:
12
//kangax.github.io/compat-table/es6/#test-WeakMap
13
14
const firstNames = new WeakMap();
15
firstNames.set(this, "Panda");
Copied!

--> 23.5 Don't save references to this. Use arrow functions or [Function#bind](https:

//developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
1
// bad
2
function foo() {
3
const self = this;
4
return function () {
5
console.log(self);
6
};
7
}
8
9
// bad
10
function foo() {
11
const that = this;
12
return function () {
13
console.log(that);
14
};
15
}
16
17
// good
18
function foo() {
19
return () => {
20
console.log(this);
21
};
22
}
Copied!

--> 23.6 A base filename should exactly match the name of its default export.

1
// file 1 contents
2
class CheckBox {
3
4
// ...
5
}
6
export default CheckBox;
7
8
9
// file 2 contents
10
export default function fortyTwo() { return 42; }
11
12
13
// file 3 contents
14
export default function insideDirectory() {}
15
16
17
// in some other file
18
19
// bad
20
import CheckBox from './checkBox';
21
// PascalCase import/export, camelCase filename
22
import FortyTwo from './FortyTwo';
23
// PascalCase import/filename, camelCase export
24
import InsideDirectory from './InsideDirectory';
25
// PascalCase import/filename, camelCase export
26
27
28
// bad
29
import CheckBox from './check_box';
30
// PascalCase import/export, snake_case filename
31
import forty_two from './forty_two';
32
// snake_case import/filename, camelCase export
33
import inside_directory from './inside_directory';
34
// snake_case import, camelCase export
35
import index from './inside_directory/index';
36
// requiring the index file explicitly
37
import insideDirectory from './insideDirectory/index';
38
// requiring the index file explicitly
39
40
41
// good
42
import CheckBox from './CheckBox';
43
// PascalCase export/import/filename
44
import fortyTwo from './fortyTwo';
45
// camelCase export/import/filename
46
import insideDirectory from './insideDirectory';
47
// camelCase export/import/directory name/implicit "index"
48
49
// ^ supports both insideDirectory.js and insideDirectory/index.js
Copied!

--> 23.7 Use camelCase when you export-default a function. Your filename should be identical to your function's name.

1
function makeStyleGuide() {
2
// ...
3
}
4
5
export default makeStyleGuide;
Copied!

--> 23.8 Use PascalCase when you export a

constructor / class / singleton / function library / bare object.
1
const AirbnbStyleGuide = {
2
es6: {},
3
};
4
5
export default AirbnbStyleGuide;
Copied!

--> 23.9 Acronyms and initialisms should always be all uppercased, or all lowercased.

1
> Why? Names are for readability, not to appease a computer algorithm.
Copied!
1
// bad
2
import SmsContainer from "./containers/SmsContainer";
3
4
// bad
5
6
const HttpRequests = [
7
// ...
8
];
9
10
// good
11
import SMSContainer from "./containers/SMSContainer";
12
13
// good
14
15
const HTTPRequests = [
16
// ...
17
];
18
19
// also good
20
21
const httpRequests = [
22
// ...
23
];
24
25
// best
26
import TextMessageContainer from "./containers/TextMessageContainer";
27
28
// best
29
30
const requests = [
31
// ...
32
];
Copied!

--> 23.10 You may optionally uppercase a

constant only if it (1) is exported, (2) is a const (it can not be reassigned), and (3) the programmer can trust it (and its nested properties) to never change.
1
> Why? This is an additional tool to assist in situations where the programmer would be unsure if a variable might ever change. UPPERCASE\_VARIABLES are letting the programmer know that they can trust the variable (and its properties) not to change.
2
3
* What about all `
4
const` variables? - This is unnecessary, so uppercasing should not be used for
5
constants within a file. It should be used for exported
6
constants however.
7
* What about exported objects? - Uppercase at the top level of export (e.g. `EXPORTED_OBJECT.key`) and maintain that all nested properties do not change.
Copied!
1
// bad
2
3
const PRIVATE_VARIABLE = "should not be unnecessarily uppercased within a file";
4
5
// bad
6
export const THING_TO_BE_CHANGED = "should obviously not be uppercased";
7
8
// bad
9
export let REASSIGNABLE_VARIABLE = "do not use let with uppercase variables";
10
11
// ---
12
13
// allowed but does not supply semantic value
14
export const apiKey = "SOMEKEY";
15
16
// better in most cases
17
export const API_KEY = "SOMEKEY";
18
19
// ---
20
21
// bad - unnecessarily uppercases key while adding no semantic value
22
export const MAPPING = {
23
KEY: "value",
24
};
25
26
// good
27
export const MAPPING = {
28
key: "value",
29
};
Copied!

Accessors

  • 24.1 Accessor functions for properties are not required.
  • 24.2 Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello').
1
// bad
2
class Dragon {
3
get age() {
4
// ...
5
}
6
7
set age(value) {
8
// ...
9
}
10
}
11
12
// good
13
class Dragon {
14
getAge() {
15
// ...
16
}
17
18
setAge(value) {
19
// ...
20
}
21
}
Copied!

--> 24.3 If the property/method is a boolean, use isVal() or hasVal().

1
// bad
2
if (!dragon.age()) {
3
return false;
4
}
5
6
// good
7
if (!dragon.hasAge()) {
8
return false;
9
}
Copied!

--> 24.4 It's okay to create get() and set() functions, but be consistent.

1
class Jedi {
2
constructor(options = {}) {
3
const lightsaber = options.lightsaber || "blue";
4
this.set("lightsaber", lightsaber);
5
}
6
7
set(key, val) {
8
this[key] = val;
9
}
10
11
get(key) {
12
return this[key];
13
}
14
}
Copied!

Events

  • 25.1 When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass an object literal (also known as a "hash") instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:
1
// bad
2
$(this).trigger("listingUpdated", listing.id);
3
4
// ...
5
6
$(this).on("listingUpdated", (e, listingID) => {
7
// do something with listingID
8
});
Copied!
1
prefer:
Copied!
1
// good
2
$(this).trigger("listingUpdated", { listingID: listing.id });
3
4
// ...
5
6
$(this).on("listingUpdated", (e, data) => {
7
// do something with data.listingID
8
});
Copied!

jQuery

  • 26.1 Prefix jQuery object variables with a $.
1
// bad
2
3
const sidebar = $(".sidebar");
4
5
// good
6
7
const $sidebar = $(".sidebar");
8
9
// good
10
11
const $sidebarBtn = $(".sidebar-btn");
Copied!

--> 26.2 Cache jQuery lookups.

1
// bad
2
function setSidebar() {
3
$(".sidebar").hide();
4
5
// ...
6
7
$(".sidebar").css({
8
"background-color": "pink",
9
});
10
}
11
12
// good
13
function setSidebar() {
14
const $sidebar = $(".sidebar");
15
$sidebar.hide();
16
17
// ...
18
19
$sidebar.css({
20
"background-color": "pink",
21
});
22
}
Copied!

--> 26.3 For DOM queries use Cascading $('.sidebar ul') or parent > child $('.sidebar > ul'). [jsPerf](https:

//jsperf.com/jquery-find-vs-context-sel/16)
  • 26.4 Use find with scoped jQuery object queries.
1
// bad
2
$("ul", ".sidebar").hide();
3
4
// bad
5
$(".sidebar").find("ul").hide();
6
7
// good
8
$(".sidebar ul").hide();
9
10
// good
11
$(".sidebar > ul").hide();
12
13
// good
14
$sidebar.find("ul").hide();
Copied!

ECMAScript 5 Compatibility

  • 27.1 Refer to [Kangax](https: //twitter.com/kangax/)'s ES5 [compatibility table](https: //kangax.github.io/es5-compat-table/).

ECMAScript 6+ (ES 2015+) Styles

  • 28.1 This is a collection of links to the various ES6+ features.
  1. 1.
    Arrow Functions
  2. 2.
    Classes
  3. 3.
    Object Shorthand
  4. 4.
    Object Concise
  5. 5.
    Object Computed Properties
  6. 6.
    Template Strings
  7. 7.
    Destructuring
  8. 8.
    Default Parameters
  9. 9.
    Rest
  10. 10.
    Array Spreads
  11. 11.
    Let and const
  12. 12.
    Exponentiation Operator
  13. 13.
    Iterators and Generators
  14. 14.
    Modules
  • 28.2 Do not use [TC39 proposals](https: //github.com/tc39/proposals) that have not reached stage 3.
    Why? [They are not finalized](https: //tc39.github.io/process-document/), and they are subject to change or to be withdrawn entirely. We want to use JavaScript, and proposals are not JavaScript yet.

Standard Library

The [Standard Library](https: //developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects) contains utilities that are functionally broken but remain for legacy reasons.
  • 29.1 Use Number.isNaN instead of global isNaN. eslint: [no-restricted-globals](https: //eslint.org/docs/rules/no-restricted-globals)
    Why? The global isNaN coerces non-numbers to numbers, returning true for anything that coerces to NaN. If this behavior is desired, make it explicit.
1
// bad
2
isNaN("1.2");
3
// false
4
isNaN("1.2.3");
5
// true
6
7
// good
8
Number.isNaN("1.2.3");
9
// false
10
Number.isNaN(Number("1.2.3"));
11
// true
Copied!

--> 29.2 Use Number.isFinite instead of global isFinite. eslint: [no-restricted-globals](https:

//eslint.org/docs/rules/no-restricted-globals)
1
> Why? The global `isFinite` coerces non-numbers to numbers, returning true for anything that coerces to a finite number. If this behavior is desired, make it explicit.
Copied!
1
// bad
2
isFinite("2e3");
3
// true
4
5
// good
6
Number.isFinite("2e3");
7
// false
8
Number.isFinite(parseInt("2e3", 10));
9
// true
Copied!

Testing

  • 30.1 Yup.
1
function foo() {
2
return true;
3
}
Copied!

--> 30.2 No, but seriously:

  • Whichever testing framework you use, you should be writing tests!
  • Strive to write many small pure functions, and minimize where mutations occur.
  • Be cautious about stubs and mocks - they can make your tests more brittle.
  • We primarily use [mocha](https: //www.npmjs.com/package/mocha) and [jest](https: //www.npmjs.com/package/jest) at Airbnb. [tape](https: //www.npmjs.com/package/tape) is also used occasionally for small, separate modules.
  • 100% test coverage is a good goal to strive for, even if it's not always practical to reach it.
  • Whenever you fix a bug, write a regression test. A bug fixed without a regression test is almost certainly going to break again in the future.

Performance

  • [On Layout & Web Performance](https: //www.kellegous.com/j/2013/01/26/layout-performance/)
  • [String vs Array Concat](https: //jsperf.com/string-vs-array-concat/2)
  • [Try/Catch Cost In a Loop](https: //jsperf.com/try-catch-in-loop-cost/12)
  • [Bang Function](https: //jsperf.com/bang-function)
  • [jQuery Find vs Context, Selector](https: //jsperf.com/jquery-find-vs-context-sel/164)
  • [innerHTML vs textContent for script text](https: //jsperf.com/innerhtml-vs-textcontent-for-script-text)
  • [Long String Concatenation](https: //jsperf.com/ya-string-concat/38)
  • [Are JavaScript functions like map(), reduce(), and filter() optimized for traversing arrays?](https: //www.quora.com/JavaScript-programming-language-Are-Javascript-functions-like-map-reduce-and-filter-already-optimized-for-traversing-array/answer/Quildreen-Motta)
  • Loading...

Resources

Learning ES6+
  • [Latest ECMA spec](https: //tc39.github.io/ecma262/)
  • [ExploringJS](https: //exploringjs.com)
  • [ES6 Compatibility Table](https: //kangax.github.io/compat-table/es6/)
  • [Comprehensive Overview of ES6 Features](http: //es6-features.org)
Read This
  • [Standard ECMA-262](https: //www.ecma-international.org/ecma-262/6.0/index.html)
Tools
  • Code Style Linters
    • [ESlint](https: //eslint.org) - [Airbnb Style .eslintrc](https: //github.com/airbnb/javascript/blob/master/linters/.eslintrc)
    • [JSHint](https: //jshint.com) - [Airbnb Style .jshintrc](https: //github.com/airbnb/javascript/blob/master/linters/.jshintrc)
  • Neutrino Preset - [@neutrinojs/airbnb](https: //neutrinojs.org/packages/airbnb/)
Other Style Guides
  • [Google JavaScript Style Guide](https: //google.github.io/styleguide/jsguide.html)
  • [Google JavaScript Style Guide (Old)](https: //google.github.io/styleguide/javascriptguide.xml)
  • [jQuery Core Style Guidelines](https: //contribute.jquery.org/style-guide/js/)
  • [Principles of Writing Consistent, Idiomatic JavaScript](https: //github.com/rwaldron/idiomatic.js)
  • [StandardJS](https: //standardjs.com)
Other Styles
  • [Naming this in nested functions](https: //gist.github.com/cjohansen/4135065) - Christian Johansen
  • [Conditional Callbacks](https: //github.com/airbnb/javascript/issues/52) - Ross Allen
  • [Popular JavaScript Coding Conventions on GitHub](http: //sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun
  • [Multiple var statements in JavaScript, not superfluous](https: //benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman
Further Reading
  • [Understanding JavaScript Closures](https: //javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll
  • [Basic JavaScript for the impatient programmer](https: //www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer
  • [You Might Not Need jQuery](https: //youmightnotneedjquery.com) - Zack Bloom & Adam Schwartz
  • [ES6 Features](https: //github.com/lukehoban/es6features) - Luke Hoban
  • [Frontend Guidelines](https: //github.com/bendc/frontend-guidelines) - Benjamin De Cock
Books
  • [JavaScript: The Good Parts](https: //www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford
  • [JavaScript Patterns](https: //www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov
  • [Pro JavaScript Design Patterns](https: //www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X) - Ross Harmes and Dustin Diaz
  • [High Performance Web Sites: Essential Knowledge for Front-End Engineers](https: //www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders
  • [Maintainable JavaScript](https: //www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas
  • [JavaScript Web Applications](https: //www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw
  • [Pro JavaScript Techniques](https: //www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig
  • [Smashing Node.js: JavaScript Everywhere](https: //www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch
  • [Secrets of the JavaScript Ninja](https: //www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault
  • [Human JavaScript](http: //humanjavascript.com) - Henrik Joreteg
  • [Superhero.js](http: //superherojs.com) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy
  • [JSBooks](https: //jsbooks.revolunet.com) - Julien Bouquillon
  • [Third Party JavaScript](https: //www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov
  • [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](https: //amzn.com/0321812182) - David Herman
  • [Eloquent JavaScript](https: //eloquentjavascript.net) - Marijn Haverbeke
  • [You Don't Know JS: ES6 & Beyond](https: //shop.oreilly.com/product/0636920033769.do) - Kyle Simpson
Blogs
  • [JavaScript Weekly](https: //javascriptweekly.com)
  • [JavaScript, JavaScript...](https: //javascriptweblog.wordpress.com)
  • [Bocoup Weblog](https: //bocoup.com/weblog)
  • [Adequately Good](https: //www.adequatelygood.com)
  • [NCZOnline](https: //www.nczonline.net)
  • [Perfection Kills](http: //perfectionkills.com)
  • [Ben Alman](https: //benalman.com)
  • [Dmitry Baranovskiy](http: //dmitry.baranovskiy.com)
  • [nettuts](https: //code.tutsplus.com/?s=javascript)
Podcasts
  • [JavaScript Air](https: //javascriptair.com)
  • [JavaScript Jabber](https: //devchat.tv/js-jabber/)

In the Wild

This is a list of organizations that are using this style guide. Send us a pull request and we'll add you to the list.
  • 123erfasst: [123erfasst/javascript](https: //github.com/123erfasst/javascript)
  • 4Catalyzer: [4Catalyzer/javascript](https: //github.com/4Catalyzer/javascript)
  • Aan Zee: [AanZee/javascript](https: //github.com/AanZee/javascript)
  • Airbnb: [airbnb/javascript](https: //github.com/airbnb/javascript)
  • AloPeyk: [AloPeyk](https: //github.com/AloPeyk)
  • AltSchool: [AltSchool/javascript](https: //github.com/AltSchool/javascript)
  • Apartmint: [apartmint/javascript](https: //github.com/apartmint/javascript)
  • Ascribe: [ascribe/javascript](https: //github.com/ascribe/javascript)
  • Avant: [avantcredit/javascript](https: //github.com/avantcredit/javascript)
  • Axept: [axept/javascript](https: //github.com/axept/javascript)
  • Billabong: [billabong/javascript](https: //github.com/billabong/javascript)
  • Bisk: [bisk](https: //github.com/Bisk/)
  • Bonhomme: [bonhommeparis/javascript](https: //github.com/bonhommeparis/javascript)
  • Brainshark: [brainshark/javascript](https: //github.com/brainshark/javascript)
  • CaseNine: [CaseNine/javascript](https: //github.com/CaseNine/javascript)
  • Cerner: [Cerner](https: //github.com/cerner/)
  • Chartboost: [ChartBoost/javascript-style-guide](https: //github.com/ChartBoost/javascript-style-guide)
  • Coeur d'Alene Tribe: [www.cdatribe-nsn.gov](https: //www.cdatribe-nsn.gov)
  • ComparaOnline: [comparaonline/javascript](https: //github.com/comparaonline/javascript-style-guide)
  • Compass Learning: [compasslearning/javascript-style-guide](https: //github.com/compasslearning/javascript-style-guide)
  • DailyMotion: [dailymotion/javascript](https: //github.com/dailymotion/javascript)
  • DoSomething: [DoSomething/eslint-config](https: //github.com/DoSomething/eslint-config)
  • Digitpaint [digitpaint/javascript](https: //github.com/digitpaint/javascript)
  • Drupal: [www.drupal.org](https: //git.drupalcode.org/project/drupal/blob/8.6.x/core/.eslintrc.json)
  • Ecosia: [ecosia/javascript](https: //github.com/ecosia/javascript)
  • Evernote: [evernote/javascript-style-guide](https: //github.com/evernote/javascript-style-guide)
  • Evolution Gaming: [evolution-gaming/javascript](https: //github.com/evolution-gaming/javascript)
  • EvozonJs: [evozonjs/javascript](https: //github.com/evozonjs/javascript)
  • ExactTarget: [ExactTarget/javascript](https: //github.com/ExactTarget/javascript)
  • Flexberry: [Flexberry/javascript-style-guide](https: //github.com/Flexberry/javascript-style-guide)
  • Gawker Media: [gawkermedia](https: //github.com/gawkermedia/)
  • General Electric: [GeneralElectric/javascript](https: //github.com/GeneralElectric/javascript)
  • Generation Tux: [GenerationTux/javascript](https: //github.com/generationtux/styleguide)
  • GoodData: [gooddata/gdc-js-style](https: //github.com/gooddata/gdc-js-style)
  • GreenChef: [greenchef/javascript](https: //github.com/greenchef/javascript)
  • Grooveshark: [grooveshark/javascript](https: //github.com/grooveshark/javascript)
  • Grupo-Abraxas: [Grupo-Abraxas/javascript](https: //github.com/Grupo-Abraxas/javascript)
  • Happeo: [happeo/javascript](https: //github.com/happeo/javascript)
  • Honey: [honeyscience/javascript](https: //github.com/honeyscience/javascript)
  • How About We: [howaboutwe/javascript](https: //github.com/howaboutwe/javascript-style-guide)
  • HubSpot: [HubSpot/javascript](https: //github.com/HubSpot/javascript)
  • Hyper: [hyperoslo/javascript-playbook](https: //github.com/hyperoslo/javascript-playbook/blob/master/style.md)
  • InterCity Group: [intercitygroup/javascript-style-guide](https: //github.com/intercitygroup/javascript-style-guide)
  • Jam3: [Jam3/Javascript-Code-Conventions](https: //github.com/Jam3/Javascript-Code-Conventions)
Last modified 1d ago